﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TsCore;

namespace TsWeb.Account
{
    public partial class CreateUsers : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindRolesToList();
            } 
        }

        protected void CreateUserButton_Click(object sender, EventArgs e)
        {
            List<String> TsRoles = new List<string>();
            foreach (RepeaterItem ri in UsersRoleList.Items)
            {
                 CheckBox RoleCheckBox = ri.FindControl("RoleCheckBox") as CheckBox;
                if (RoleCheckBox.Checked)
                    TsRoles.Add(RoleCheckBox.Text);
            } 
            TsSystem.Instance.CreateNewUser(NameTxt.Text, SurnameTxt.Text, UserNameTxt.Text, PasswordTxt.Text, EmailTxt.Text, TsRoles.ToArray());

        }



        private void BindRolesToList()
        {
            string[] roles = TsSystem.Instance.GetRoles();
            UsersRoleList.DataSource = roles;
            UsersRoleList.DataBind();
        }

    }
}